//
//  HistoryListVC.m
//  Dormitory2404
//
//  Created by gleeman.G on 2017/12/25.
//  Copyright © 2017年 Hainan Suyun network technology co. LTD. All rights reserved.
//

#import "HistoryListVC.h"
#import <YYKit/YYKit.h>
#import "History.h"
#import "HistoryDetail.h"

@interface HistoryListVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation HistoryListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"历史账单";
    [self tableViewSetting];
}

- (void)tableViewSetting
{
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate =  self;
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    cell = [cell initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    
//    cell.textLabel.tex
    History *his =[HistoryList shareInstance].historyList[indexPath.row];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设置格式：zzz表示时区
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    //NSDate转NSString
    NSString *currentDateString = [dateFormatter stringFromDate:his.date];
    
    cell.textLabel.text = currentDateString;

    cell.detailTextLabel.text = [NSString stringWithFormat:@"花费%.2f元",his.totalPrice];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return [HistoryList shareInstance].historyList.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HistoryDetail *vc = [[HistoryDetail alloc]init];
    vc.index = indexPath.row;
    [self.navigationController pushViewController:vc animated:YES];
    
}


- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
    }
    return _tableView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
